<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
</body>
<script type="text/javascript" src="js/JnPakg.js"></script>
<script type="text/javascript">
(function(){
	dw("08_prototype的继承[2].html");
})();


//实现继承有两种方法,一种是构造继承法,一种是原型继承法
var A = function(_size){
	dw("A的构造方法被执行了")
	var n = _size;
	this.size = function(){return n;}
}
A.prototype.maxSize = function(){return "max : "+this.size();}
A.prototype.x = 5;

var a = new A(5);
dw("A.size()" + a.size());
dw("A.maxSize()" + a.maxSize());
dw.dl();

/**原型继承.[有缺陷]
**/
var B1 = function(){
	dw("B1的构造方法被执行了");
}
B1.prototype = new A(); //有缺陷,所有通过B1构建的A都指向同一个A的实例,一个改变都改变了.
//B1.prototype = A.prototype; //有缺陷,没有办法继承A的动态共有变量和属性,修改B1的prototype对象A的也被改了
B1.prototype.y = 6;
var b1 = new B1();
dw(b1.x);
dw(b1.y);
dw("B1.maxSize()" + b1.maxSize());//当[B1.prototype = A.prototype]执行会出错
if(b1 instanceof B1){
	dw("b1是B1")
}else{
	dw("否")
}
if(b1 instanceof A){
	dw("b1是A")
}else{
	dw("否")
}
dw.dl();

var a1 = new A(15);
dw("a1.y : "+a1.y);




</script>
</html>